package cn.zf233.xcloud.entity;

import cn.zf233.xcloud.commom.annotations.FillCreate;
import cn.zf233.xcloud.commom.annotations.FillUpdate;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.io.Serializable;

/**
 * Created by zf233 on 2020/11/4
 */
@Document(indexName = "file")
public class File implements Serializable {

    private static final long serialVersionUID = 8857945259217487581L;

    @Id
    private Long id;
    @Field(type = FieldType.Integer)
    private Long userId;
    @Transient
    private Long parentId;
    @Transient
    private Long shareId;
    @Field(type = FieldType.Integer)
    private Integer folder;
    @Transient
    private String randomFileName;
    @Field(type = FieldType.Text, analyzer = "ik_max_word", searchAnalyzer = "ik_max_word")
    private String oldFileName;
    @Transient
    private String highLightFileName;
    @Field(type = FieldType.Long)
    private Long fileSize;
    @Transient
    private String fileType;
    @Field(type = FieldType.Integer)
    private Integer classify;
    @Field(type = FieldType.Integer)
    private Integer deleteFlag;
    @FillCreate
    @Field(type = FieldType.Long)
    private Long uploadTime;
    @FillUpdate
    @Transient
    private Long updateTime;

    @JsonIgnore
    public boolean isAFolder() {
        return this.folder == 1;
    }

    @JsonIgnore
    public boolean isDeleted() {
        return this.deleteFlag == 1;
    }

    public File() {
    }

    public File(Long id, Long userId, Long parentId, Long shareId, Integer folder, String randomFileName, String oldFileName, String highLightFileName, Long fileSize, String fileType, Integer classify, Integer deleteFlag, Long uploadTime, Long updateTime) {
        this.id = id;
        this.userId = userId;
        this.parentId = parentId;
        this.shareId = shareId;
        this.folder = folder;
        this.randomFileName = randomFileName;
        this.oldFileName = oldFileName;
        this.highLightFileName = highLightFileName;
        this.fileSize = fileSize;
        this.fileType = fileType;
        this.classify = classify;
        this.deleteFlag = deleteFlag;
        this.uploadTime = uploadTime;
        this.updateTime = updateTime;
    }

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public Long getParentId() {
        return parentId;
    }

    public void setParentId(Long parentId) {
        this.parentId = parentId;
    }

    public Long getShareId() {
        return shareId;
    }

    public void setShareId(Long shareId) {
        this.shareId = shareId;
    }

    public Integer getFolder() {
        return folder;
    }

    public void setFolder(Integer folder) {
        this.folder = folder;
    }

    public String getRandomFileName() {
        return randomFileName;
    }

    public void setRandomFileName(String randomFileName) {
        this.randomFileName = randomFileName;
    }

    public String getOldFileName() {
        return oldFileName;
    }

    public void setOldFileName(String oldFileName) {
        this.oldFileName = oldFileName;
    }

    public String getHighLightFileName() {
        return highLightFileName;
    }

    public void setHighLightFileName(String highLightFileName) {
        this.highLightFileName = highLightFileName;
    }

    public Long getFileSize() {
        return fileSize;
    }

    public void setFileSize(Long fileSize) {
        this.fileSize = fileSize;
    }

    public String getFileType() {
        return fileType;
    }

    public void setFileType(String fileType) {
        this.fileType = fileType;
    }

    public Integer getClassify() {
        return classify;
    }

    public void setClassify(Integer classify) {
        this.classify = classify;
    }

    public Integer getDeleteFlag() {
        return deleteFlag;
    }

    public void setDeleteFlag(Integer deleteFlag) {
        this.deleteFlag = deleteFlag;
    }

    public Long getUploadTime() {
        return uploadTime;
    }

    public void setUploadTime(Long uploadTime) {
        this.uploadTime = uploadTime;
    }

    public Long getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Long updateTime) {
        this.updateTime = updateTime;
    }

    @Override
    public String toString() {
        return "File{" +
                "id=" + id +
                ", userId=" + userId +
                ", parentId=" + parentId +
                ", shareId=" + shareId +
                ", folder=" + folder +
                ", randomFileName='" + randomFileName + '\'' +
                ", oldFileName='" + oldFileName + '\'' +
                ", highLightFileName='" + highLightFileName + '\'' +
                ", fileSize=" + fileSize +
                ", fileType='" + fileType + '\'' +
                ", classify=" + classify +
                ", deleteFlag=" + deleteFlag +
                ", uploadTime=" + uploadTime +
                ", updateTime=" + updateTime +
                '}';
    }
}